<template>
	<view>
		<u-subsection :list="HospitalList" keyName="campusName" :current="index" change="change" @change="change">

		</u-subsection>

		<view @click="selectDepartment(r.id)" style="height: 60px;background-color:aliceblue"
			v-for="(r,index) in DepartmentList" :key="index">
			<p style="font-size: 18px;padding-left: 20px;color: #333333;padding-top: 20px;">{{r.divisionName}}</p>
		</view>
			<!-- <image style="height: 60px;width: 60px;margin-right: 10px;" src="../../static/316663.jpg">
			</image> -->
		<view>
			<u-picker :show="show" :columns="columns" keyName="divisionName" @change="change2" @cancel="cancel"
				@confirm="confirm">
				</u-picker>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {

				userId: 1,
				DepartmentList: [],
				HospitalList: [],
				index: '',
				index2:0,
				//院区id
				HospitalId: '',
				//一级科室Id
				DepartmentId1:'',
				//二级科室Id
				DepartmentId2:'',
				curNow: 0,
				indexList: [],
				title: '选择科室',
				// list: [],
				columns: [],
				c:[],
				show: false,
				department1:'',
				department2:'',
			}
		},
		onLoad() {

			//this.userId = uni.getStorageSync('userId')
			//console.log(this.userId)
			//查询所有院区
			this.getHospitals();
			if (this.HospitalId == '') {
				this.HospitalId = 1
			}
			this.getDepartments();
		},
		methods: {

			selectDepartment(id) {
				this.show = true
				console.log("科室"+id)
				this.DepartmentId1 = id
				//console.log("准备发送请求")
				this.$axios.get("/other/other/division-type/selectDepartment/" + id).then((
						res) => {
						
						//console.log(res.data.data.department)
						this.c=[]
						this.c = res.data.data.department
						//console.log(this.c)
						this.columns = []
						this.columns.push(this.c)
						//console.log(this.columns)
						

					})
					.catch((error) => {
						console.log(error);
					});

			},
			change(index) {
				this.index = index
				this.HospitalId = this.HospitalList[this.index].id
				console.log(this.HospitalId)
				this.getDepartments();

			},
			getDepartments() {
				this.$axios.get("/other/other/division-type/getDepartments/" + this.HospitalId).then((
						res) => {
						//console.log("成功")
						this.DepartmentList = res.data.data.list
					})
					.catch((error) => {
						console.log(error);
					});
			},
			getHospitals() {
				this.$axios.get("/user/user/campus/getHospitals/").then((
						res) => {
						//console.log("成功")
						this.HospitalList = res.data.data.list
					})
					.catch((error) => {
						console.log(error);
					});
			},
			change2(e) {
				 console.log('change', e.value[0]);
			},
			confirm(e) {
				// console.log('confirm', e);
				this.show = false
				this.DepartmentId2 = e.value[0].id
				
				
				
				//院区Id
				uni.setStorage({
					key: 'HospitalId',
					data: this.HospitalId,
					success() {
						console.log('院区id存储成功')
					}
				})
				console.log("院区id="+this.HospitalId)
				
				//一级科室Id
				uni.setStorage({
					key: 'DepartmentId1',
					data: this.DepartmentId1,
					success() {
						console.log('一级科室id存储成功')
					}
				})
				
				//二级科室Id
				uni.setStorage({
					key: 'DepartmentId2',
					data: this.DepartmentId2,
					success() {
						console.log('二级科室id存储成功')
					}
				})
				//alert(this.department2)
				// let url;
				// uni.getStorage({
				// 	key: 'selectPatientAfterUrl',
				// 	success:function(res){
				// 		alert(JSON.stringify(res))
				// 		url=res.data
				// 	}
				// })
				
				setTimeout(() => {
					//跳转非pages.json>tabbar>配置过的页面，使用navigateTo
					// uni.navigateBack(OBJECT)({
					// uni.navigateTo({
					uni.navigateTo({
						url: '../zqw/show'
					})
				}, 1000)
			},
			cancel() {
				this.show = false
			}

		}
	}
</script>

<style>

</style>
